# Maintainer: Andreas Radke <andyrtr@archlinux.org>

pkgname=claws-mail
pkgver=4.0.0
pkgrel=2
pkgdesc="A GTK+ based e-mail client"
arch=('x86_64')
license=('GPL3')
url="https://www.claws-mail.org"
depends=('gtk3' 'gnutls' 'startup-notification' 'enchant' 'gpgme'
         'libetpan' 'compface' 'libsm' 'dbus-glib')
makedepends=('spamassassin' 'bogofilter' 'networkmanager' 'valgrind'
             # dependencies for plugins
             'libgdata' 'libnotify' 'libcanberra' 'poppler-glib' 'libytnef' 'libical'
             'dillo' 'python' 'gumbo-parser'
             # deps to build the docs
             'docbook-utils' 'texlive-formatsextra')
optdepends=('python:           needed for some tools'
            'perl:              needed for some tools and perl plugin'
            'spamassassin:      adds support for spamfiltering'
            'bogofilter:        adds support for spamfiltering'
            'libnotify:         for notification plugin'
            'libcanberra:       for notification plugin'
            'dbus:              for notification plugin'
            'libxml2:           for rssyl plugins'
            'curl:              for vcalendar, rssyl and spamreport plugins'
            'libarchive:        for archive plugin and various other plugins'
            'libytnef:          for tnef_parse plugin'
            'libgdata:          for gdata plugin'
            'poppler-glib:      for pdf viewer plugin'
            'ghostscript:       for pdf viewer plugin'
            'libical:           for vcalendar plugin'
            'dillo:             for dillo html viewer plugin'
            'webkit2gtk:        for fancy webkit html viewer plugin'
            'gumbo-parser:      for litehtml plugin')
provides=('claws')
install=$pkgname.install
source=(https://www.claws-mail.org/download.php?file=releases/claws-mail-$pkgver.tar.xz{,.asc}
        0001_move_OAuth2_to_last_place_in_auto_auth_selection.diff
        0002_Fancy_crashes_when_opening_an_email.diff
        bash_completion)
sha256sums=('4af2bd26a5d91eacb2a9c09f67a6a46c2222b40817c1f525dc050bdc7b0ee475'
            'SKIP'
            'ffd5dfe8929a86667218512095a794263a2ae56fae4add83d3ad987f94e7f786'
            'f56256a9535958063b966ab52abdf787422ff71ed2a5c41b3d9fea8716defe85'
            '3f6c248b8658cd7a62186bff572cce2525712a498f363cbbda1ed459021c28cb')
validpgpkeys=('8B3B297A03468356692F8D592CD716D654D6BBD4') # Paul <paul@claws-mail.org>


prepare() {
  cd "${pkgname}"-${pkgver}
  # upstream fixes
  patch -Np1 -i ../0001_move_OAuth2_to_last_place_in_auto_auth_selection.diff
  patch -Np1 -i ../0002_Fancy_crashes_when_opening_an_email.diff
}

build() {
  cd "${pkgname}"-${pkgver}
  ./configure --prefix=/usr --disable-static \
    --enable-enchant \
    --enable-gnutls \
    --enable-ldap \
    --enable-crash-dialog \
    --enable-pgpmime-plugin \
    --enable-spamassassin-plugin \
    --enable-bogofilter-plugin \
    --enable-fancy-plugin \
    --enable-manual
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package() {
  cd "${pkgname}"-${pkgver}
  make DESTDIR="${pkgdir}" install

  install -Dm 644 "$srcdir"/bash_completion "${pkgdir}"/usr/share/bash-completion/completions/claws-mail

  # install extra tools
  cd tools
  install -m755 -d "${pkgdir}"/usr/lib/claws-mail/tools
  for files in *.pl *.py *.sh *.conf tb2claws-mail update-po uudec uuooffice README; do
    cp -arv $files "${pkgdir}"/usr/lib/claws-mail/tools/
  done
}
